﻿using Microsoft.AspNetCore.SignalR;
using System;
using System.Threading.Tasks;

namespace Yozeev.SignalR
{
    public class BoatHub : Hub
    {
        public Task JoinGroup(string groupName)
        {
            return Groups.AddToGroupAsync(Context.ConnectionId, groupName);
        }

        public async Task NewMessage(long username, string message)
        {
            await Clients.All.SendAsync("messageReceived", username, message);
        }

        public async Task UpdateSchedule(string groupName, string scheduleCode, string scheduleName, 
            string startTime, string endTime, string date)
        {
            await Clients.Group(groupName).SendAsync("updateSchedule", scheduleCode, scheduleName,
            startTime, endTime, date);
        }

        public async Task AddTicket(string groupName, string ticketName, string customerName, int price, string cardName)
        {
            await Clients.Group(groupName).SendAsync("addTicket", ticketName, customerName, price, cardName);
        }

        public async Task DeleteTicket(string groupName, int index)
        {
            await Clients.Group(groupName).SendAsync("deleteTicket", index);
        }
    }
}
